package com.cryptoneedle.center.source.entity.metadata;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.source.key.metadata.DatabaseKey;
import com.cryptoneedle.center.source.key.metadata.TableKey;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>description: 源数据源-表 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-19
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@jakarta.persistence.Table(schema = "public", name = "source_table")
@IdClass(TableKey.class)
@Comment("源数据源-表")
public class Table extends BaseEntity {

    @Id
    @Comment("源数据源-目录名称")
    private String catalogName;
    @Id
    @Comment("源数据源-数据库名称")
    private String databaseName;
    @Id
    @Comment("源数据源-表名称")
    private String tableName;

    @jakarta.persistence.Column(columnDefinition = "TEXT")
    @Comment("源数据源-表评论")
    private String comment;
    @Comment("源数据源统计信息-数据量")
    private Long rowCount;
    @jakarta.persistence.Column(precision = 30, scale = 20)
    @Comment("源数据源统计信息-行平均字节数")
    private Long avgRowLen;
    @Comment("源数据源统计信息-预估占用空间(单位：MB)")
    private BigDecimal estimateMegaBytes;
    @Comment("源数据源统计信息-统计时间")
    private Date statisticDt;

    @Comment("源数据源-维度名称")
    private String activeDimensionName;
    @Comment("源数据源-Doris目录编码")
    private String dorisCatalogName;
    @Comment("源数据源-系统编码")
    private String systemCode;
    @Comment("源数据源-启用表")
    private Boolean enabled;

    @Comment("转换-表名称")
    private String transTableName;
    @jakarta.persistence.Column(columnDefinition = "TEXT")
    @Comment("转换-人工指定表名称")
    private Boolean transTableNameManual;
    @Comment("转换-表评论")
    private String transComment;
    @Comment("转换-人工指定表评论")
    private Boolean transCommentManual;
    @Comment("转换-分桶数量")
    private Integer transBucketCount;

    /**
     * Key
     */

    public DatabaseKey databaseKey() {
        return BeanUtil.copyProperties(this, DatabaseKey.class);
    }

    public TableKey tableKey() {
        return BeanUtil.copyProperties(this, TableKey.class);
    }
}